<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateShopsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shops', function (Blueprint $table) {
            $table->increments('id');
            $table->string('sname')->comment('货品名称');
            $table->string('price')->comment('货品价格');
            $table->smallInteger('kucun')->comment('货品的库存数量');
            $table->string('attrs')->comment('货品的属性组合');
            $table->unsignedInteger('goods_id')->comment('当前货品所属的商品id');
            //给当前表中的goods_id字段添加外键约束

            //foreign()方法代表当前表中的哪一个字段收到外键的约束
            //references()方法代表当前表中被外键约束的字段受到哪个字段的约束
            //on()方法代表当前表中被外键约束的字段受到来自哪一个表的约束
            //onDelete()方法里面的参数是固定的
            $table->foreign('goods_id')->references('id')->on('goods')->onDelete('cascade');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('shops');
    }
}
